package com.kk.exceptions;

/**
 * @author kl
 * @version 1.0
 * @description: TODO
 * @date 2025/10/14 上午10:51
 */

import com.kk.common.IResultCode;
import com.kk.common.ResultCode;

import java.io.Serial;

/**
 * 业务异常类
 * 用于业务逻辑中主动抛出的异常
 *
 * @author Your Name
 * @since 1.0.0
 */
public class BusinessException extends RuntimeException {

    @Serial
    private static final long serialVersionUID = 1L;

    /**
     * 错误码
     */
    private Integer code;

    /**
     * 错误消息
     */
    private String message;

    /**
     * 默认构造方法
     */
    public BusinessException() {
        super(ResultCode.BUSINESS_ERROR.getMessage());
        this.code = ResultCode.BUSINESS_ERROR.getCode();
        this.message = ResultCode.BUSINESS_ERROR.getMessage();
    }

    /**
     * 构造方法（自定义消息）
     */
    public BusinessException(String message) {
        super(message);
        this.code = ResultCode.BUSINESS_ERROR.getCode();
        this.message = message;
    }

    /**
     * 构造方法（使用状态码枚举）
     */
    public BusinessException(IResultCode resultCode) {
        super(resultCode.getMessage());
        this.code = resultCode.getCode();
        this.message = resultCode.getMessage();
    }

    /**
     * 构造方法（自定义状态码和消息）
     */
    public BusinessException(Integer code, String message) {
        super(message);
        this.code = code;
        this.message = message;
    }

    /**
     * 构造方法（带原因）
     */
    public BusinessException(String message, Throwable cause) {
        super(message, cause);
        this.code = ResultCode.BUSINESS_ERROR.getCode();
        this.message = message;
    }

    /**
     * 构造方法（使用状态码枚举+原因）
     */
    public BusinessException(IResultCode resultCode, Throwable cause) {
        super(resultCode.getMessage(), cause);
        this.code = resultCode.getCode();
        this.message = resultCode.getMessage();
    }

    /**
     * 构造方法（完整参数）
     */
    public BusinessException(Integer code, String message, Throwable cause) {
        super(message, cause);
        this.code = code;
        this.message = message;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    @Override
    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }
}